import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  LIST_URL = '/system/app/page',
  SAVE_URL = '/system/app/create',
  UPDATE_URL = '/system/app/update',
  DELETE_URL = '/system/app/delete',
  DELETE_BATCH_URL = '/system/app/deleteBatch',
}

/**
 * 系统应用列表
 * @param params
 */
export const pageList = (params) => defHttp.get({ url: Api.LIST_URL, params });

/**
 * 保存或者更新系统应用
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.UPDATE_URL : Api.SAVE_URL;
  return defHttp.post({ url: url, params });
};

/**
 * 删除系统应用
 * @param id
 * @param handleSuccess
 */
export const deleteById = (id, reload) => {
  return defHttp.delete({ url: Api.DELETE_URL + `/${id}` }).then(() => {
    reload();
  });
};

/**
 * 批量删除系统应用
 * @param params
 * @param reload
 */
export const deleteBatch = (params, reload) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp
        .delete(
          {
            url: Api.DELETE_BATCH_URL,
            data: params,
          },
          { joinParamsToUrl: true },
        )
        .then(() => {
          reload();
        });
    },
  });
};
